<template>
	<view class="wrap">
		<js-error mode="bottom" ref="jsError"></js-error>
		<scroll-view class="scroll-list bg-white" scroll-y="true" :style="[{height:stockListHeight + 'px'}]">
			<u-form class="form bg-white" :model="model" ref="uForm" label-position="left">
				<u-form-item label="存货编码:" prop="cinvCode" label-width="180" :label-style="{'font-weight':'bold'}">
					<view>{{model.basInv.cinvcode}}</view>
				</u-form-item>
				<u-form-item label="存货代码:" prop="cinvName" label-width="180" :label-style="{'font-weight':'bold'}">
					<view>{{model.basInv.cinvaddcode}}</view>
				</u-form-item>
				<u-form-item label="存货名称:" prop="cinvName" label-width="180" :label-style="{'font-weight':'bold'}">
					<view>{{model.basInv.cinvname}}</view>
				</u-form-item>
				<u-form-item label="仓库:" prop="cwhCode" label-width="180" :label-style="{'font-weight':'bold'}">
					<view>{{model.cwhcode}}</view>
				</u-form-item>
				<u-form-item label="批次:" prop="cbatch" label-width="180" :label-style="{'font-weight':'bold'}">
					<view>{{model.cbatch}}</view>
				</u-form-item>
				<u-form-item label="数量:" prop="iqty" label-width="180" :label-style="{'font-weight':'bold'}">
					<view>{{model.iqty}}</view>
				</u-form-item>
				<u-form-item v-if="showflag != 1" label="验证:" prop="cbatch" label-width="180" :label-style="{'font-weight':'bold'}">
					<u-button slot="right" type="primary" @click="search" v-if="!flag">扫一扫</u-button>
					<view v-else>已验证</view>
				</u-form-item>
				<u-form-item v-if="showflag != 1" label="验证数量:" prop="cbatch" label-width="180" :label-style="{'font-weight':'bold'}">
					<view>{{iqty}}</view>
				</u-form-item>
				<u-form-item label="货位:" prop="cbatch" label-width="180"  :label-style="{'font-weight':'bold'}">
					<u-input placeholder="请选择货位" v-model="cposCodeAndName" @click="region" disabled="disabled" type="select" di
						maxlength="64"></u-input>
				</u-form-item>
			</u-form>
		</scroll-view>
		
		<view class="footer">
			<view class="confrim-btn padding padding-bottom-sm flex bg-white">
				<u-button  type="primary" class="btn" style="width: 100%;" @click="submit">提交</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				stockListHeight: 0,
				barcode:'', //AA01|01GD02001000I010|SPHC 2.0*262*C|Z11106202310301-4231031124239004|001|3380|1|202311011010|0AAA||202310301-4||9120963|11106||||||
				showflag:0,
				model:{id: '',},
				iqty:'',
				cposCodeAndName:'',
				cposcode:'',//货位号
				flag:false,
			}
		},
		onLoad(params) {
			var data = JSON.parse(params.data)
			this.model = data;
			this.showflag=params.showflag?params.showflag:0
			
			var _self = this;
			uni.getSystemInfo({
				success: (e) => { // resu 可以获取当前屏幕的高度
					_self.stockListHeight = e.windowHeight - uni.upx2px(160);
				},
				fail: (res) => {}
			});
			
			uni.$on('consult', (item) => {
				this.cposCodeAndName = item.cposcode + ' - ' + item.cposname;
				this.cposcode = item.cposcode;
			})
		},
		watch: {
		
		},
		onShow() {},
		onReady() {},
		methods: {
			region(){
				uni.navigateTo({
					url: '/pages/asd/index/cgsj/region?cwhcode='+this.model.cwhcode
				})
			},
			
			search(){
				var _this = this;
				uni.scanCode({ 
					onlyFromCamera: true,
					success: function(res) {
						this.loadData(res.result);
					}.bind(this)
				});
				
				// this.loadData(this.barcode);
			},
			
			loadData(barcode){
				this.$u.api.asdApi.checkSlByCode({barcode:barcode,id:this.model.id}).then(res => {
					if(res.result == 'false'){
						this.$refs.jsError.showError('',res.message,'error');
					}else{
						this.flag = res.flag
						this.iqty = res.iqty;
					}
				})
			},
			
			async submit() {
				var i = await this.checkData();
				if(i == 'suc'){
					this.$u.api.asdApi.upDataToU8({id:this.model.id,cposcode:this.cposcode}).then(res => {
						uni.showModal({
							title: '提示',
							content: res.message,
							showCancel: false,
							success: (res) => {}
						});
						if(res.result == 'true'){
							uni.navigateBack({
								delta: 1,
							})
						}
					})
				}
			},
			
			checkData(){
				const _this = this;
				return new Promise((resolve,reject) =>{
					if(_this.cposcode == undefined || _this.cposcode == ''){
						_this.$refs.jsError.showError('','请选择货位！','error');
						resolve("err");
					}
					if(!_this.flag){
						_this.$refs.jsError.showError('','请验证现品票！','error');
						resolve("err");
					}
					resolve("suc");
				})
			},
		}
	}
</script>
<style>
	@import '../asd.css';
</style>
